//
//  NSData+TZExtension.h
//  TZOCExtension
//
//  Created by Tim.Z on 2017/1/15.
//  Copyright © 2017年 Tim.Z. All rights reserved.
//

#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN

@interface NSData (TZExtension)
#pragma mark - Hash
    ///=============================================================================
    /// @name Hash
    ///=============================================================================

/**
 Returns a lowercase NSString for md2 hash.
 */
- (NSString *)tz_md2String;

/**
 Returns an NSData for md2 hash.
 */
- (NSData *)tz_md2Data;

/**
 Returns a lowercase NSString for md4 hash.
 */
- (NSString *)tz_md4String;

/**
 Returns an NSData for md4 hash.
 */
- (NSData *)tz_md4Data;

/**
 Returns a lowercase NSString for md5 hash.
 */
- (NSString *)tz_md5String;

/**
 Returns an NSData for md5 hash.
 */
- (NSData *)tz_md5Data;

/**
 Returns a lowercase NSString for sha1 hash.
 */
- (NSString *)tz_sha1String;

/**
 Returns an NSData for sha1 hash.
 */
- (NSData *)tz_sha1Data;

/**
 Returns a lowercase NSString for sha224 hash.
 */
- (NSString *)tz_sha224String;

/**
 Returns an NSData for sha224 hash.
 */
- (NSData *)tz_sha224Data;

/**
 Returns a lowercase NSString for sha256 hash.
 */
- (NSString *)tz_sha256String;

/**
 Returns an NSData for sha256 hash.
 */
- (NSData *)tz_sha256Data;

/**
 Returns a lowercase NSString for sha384 hash.
 */
- (NSString *)tz_sha384String;

/**
 Returns an NSData for sha384 hash.
 */
- (NSData *)tz_sha384Data;

/**
 Returns a lowercase NSString for sha512 hash.
 */
- (NSString *)tz_sha512String;

/**
 Returns an NSData for sha512 hash.
 */
- (NSData *)tz_sha512Data;

/**
 Returns a lowercase NSString for hmac using algorithm md5 with key.
 @param key  The hmac key.
 */
- (NSString *)tz_hmacMD5StringWithKey:(NSString *)key;

/**
 Returns an NSData for hmac using algorithm md5 with key.
 @param key  The hmac key.
 */
- (NSData *)tz_hmacMD5DataWithKey:(NSData *)key;

/**
 Returns a lowercase NSString for hmac using algorithm sha1 with key.
 @param key  The hmac key.
 */
- (NSString *)tz_hmacSHA1StringWithKey:(NSString *)key;

/**
 Returns an NSData for hmac using algorithm sha1 with key.
 @param key  The hmac key.
 */
- (NSData *)tz_hmacSHA1DataWithKey:(NSData *)key;

/**
 Returns a lowercase NSString for hmac using algorithm sha224 with key.
 @param key  The hmac key.
 */
- (NSString *)tz_hmacSHA224StringWithKey:(NSString *)key;

/**
 Returns an NSData for hmac using algorithm sha224 with key.
 @param key  The hmac key.
 */
- (NSData *)tz_hmacSHA224DataWithKey:(NSData *)key;

/**
 Returns a lowercase NSString for hmac using algorithm sha256 with key.
 @param key  The hmac key.
 */
- (NSString *)tz_hmacSHA256StringWithKey:(NSString *)key;

/**
 Returns an NSData for hmac using algorithm sha256 with key.
 @param key  The hmac key.
 */
- (NSData *)tz_hmacSHA256DataWithKey:(NSData *)key;

/**
 Returns a lowercase NSString for hmac using algorithm sha384 with key.
 @param key  The hmac key.
 */
- (NSString *)tz_hmacSHA384StringWithKey:(NSString *)key;

/**
 Returns an NSData for hmac using algorithm sha384 with key.
 @param key  The hmac key.
 */
- (NSData *)tz_hmacSHA384DataWithKey:(NSData *)key;

/**
 Returns a lowercase NSString for hmac using algorithm sha512 with key.
 @param key  The hmac key.
 */
- (NSString *)tz_hmacSHA512StringWithKey:(NSString *)key;

/**
 Returns an NSData for hmac using algorithm sha512 with key.
 @param key  The hmac key.
 */
- (NSData *)tz_hmacSHA512DataWithKey:(NSData *)key;

/**
 Returns a lowercase NSString for crc32 hash.
 */
- (NSString *)tz_crc32String;

/**
 Returns crc32 hash.
 */
- (uint32_t)tz_crc32;

#pragma mark - Encode and decode
    ///=============================================================================
    /// @name Encode and decode
    ///=============================================================================

/**
 Returns string decoded in UTF8.
 */
- (nullable NSString *)tz_utf8String;

/**
 Returns a uppercase NSString in HEX.
 */
- (nullable NSString *)tz_hexString;

/**
 Returns an NSData from hex string.
 
 @param hexString   The hex string which is case insensitive.
 
 @return a new NSData, or nil if an error occurs.
 */
+ (nullable NSData *)tz_dataWithHexString:(NSString *)hexString;

/**
 Returns an NSString for base64 encoded.
 */
- (nullable NSString *)tz_base64EncodedString;

/**
 Returns an NSData from base64 encoded string.
 
 @warning This method has been implemented in iOS7.
 
 @param base64EncodedString  The encoded string.
 */
+ (nullable NSData *)tz_dataWithBase64EncodedString:(NSString *)base64EncodedString;

/**
 Returns an NSDictionary or NSArray for decoded self.
 Returns nil if an error occurs.
 */
- (nullable id)tz_jsonValueDecoded;


@end
NS_ASSUME_NONNULL_END
